// JointFunction.h: interface for the JointFunction class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_JOINTFUNCTION_H__214522CB_58E6_40C8_9F89_DC0DC7E73629__INCLUDED_)
#define AFX_JOINTFUNCTION_H__214522CB_58E6_40C8_9F89_DC0DC7E73629__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "FunctionObject.h"
#include "JointPortFormer.h"
#include "JointPort.h"
#include "JointPart.h"
#include "UeVector.h"
#include "Part.h"
class Joint;
 
class AFX_EXT_CLASS JointFunction : public FunctionObject  
{
	DECLARE_DYNAMIC_CREATE(JointFunction)
protected:
	JointFunction();

public:	
	enum{
		eEXTERNALTHREAD_RH = 1,
		eINTERNALTHREAD_RH = 2,
		eEXTERNALTHREAD_LH = 3,
		eINTERNALTHREAD_LH = 4,
		eRODHOLE = 5,
		eEYE = 12,
		ePIPECLAMP = 31,
		ePINBOLTFOREYE = 10,
		ePIPE = 30,
		eCONSTSPRINGEXTERNALTHREAD_RH = 64,
		eCONSTSPRINGEXTERNALTHREAD_LH = 65,
		eCONSTSPRINGINTERNALTHREAD_RH = 62,
		eCONSTSPRINGINTERNALTHREAD_LH = 63,
		eCONSTSPRINGEYE = 66,
		eCONSTSPRINGJOINTPORT = 993
	};

public:
	virtual ~JointFunction();

public:
	Joint* GetJoint(){
		return m_pJoint;
	}

	void SetJoint(Joint* pJoint);

	virtual BOOL AttachTo(JointFunction* pJointFunction){return TRUE;}

	BOOL HasJoint(){
		return m_bHasJoint;
	}

	INT GetJointStyle(){
		return m_nJointStyle;
	}

	void JointStyle(INT nStyle){
		m_nJointStyle = nStyle;
	}

	void CutJoint();

	JointSystem::JointPortFormer* GetFormer();

	const CString& JointPortID();
	void JointPortID(const CString& strID){
		m_strPortID = strID;
	}

	void SetMainVector(UeVector& vector){
		m_vZ = vector;
	}

	UeVector GetMainVector(){
		return m_vZ;
	}

	void SetSideVector(UeVector& vector){
		m_vX = vector;
	}

	UeVector GetSideVector(){
		return m_vX;
	}

	UeVector GetForce(){
		return m_vForce;
	}

	void SetForce(UeVector& vector){
		m_vForce = vector;
	}

	BOOL IsInstantiation();

	virtual JointSystem::JointPort* jointPort();

	virtual AcGeMatrix3d CoordinateInOwner(){
		jointPort();
		return m_pPort->CoordinateInOwner();
	}

	virtual AcGePoint3d PositionInOwner(){
		jointPort();
		AcGeMatrix3d matrix(m_pPort->CoordinateInOwner());
		AcGePoint3d OriginalPt;
		AcGeVector3d vX;
		AcGeVector3d vY;
		AcGeVector3d vZ;
		matrix.getCoordSystem(OriginalPt, vX, vY, vZ);
		return OriginalPt;
	}

	virtual void SetOwner(Part* pPart){
		FunctionObject::SetOwner(pPart);
		m_JointPart.SetProperties( pPart->GetPropertyStack() );
	}

	virtual void RegisterToSupport();
	virtual void RegisterToString();
	virtual void UnRegisterToSupport();
	virtual void UnRegisterToString();

	JointFunction* GetOtherSide();

	virtual BOOL IsFixed();

	FreeField& freeField(){
		return m_FreeField;
	}

	PropertySystem::PropertyStack& GetPropertyStack() {
		return GetFormer()->GetPropertyStack();
	}

protected:
	JointSystem::JointPart& jointPart(){
		return m_JointPart;
	}

	JointSystem::JointPort* m_pPort;
private:
	Joint* m_pJoint;
	BOOL m_bHasJoint;
	JointSystem::JointPart m_JointPart;
	UeVector m_vZ;
	UeVector m_vX;
	UeVector m_vForce;
	INT m_nJointStyle;
	CString m_strPortID;
	FreeField m_FreeField;
};

#endif // !defined(AFX_JOINTFUNCTION_H__214522CB_58E6_40C8_9F89_DC0DC7E73629__INCLUDED_)
